#include "Session.h"

#include "StartScreen.h"
#include "EndScreen.h"
#include "NameScreen.h"
#include "ContentScreen.h"

Session::Session(){

	



}

void Session::init(){

	removeChildren();
	//Radiant::IntrusivePtr<AbstractScreen> currentScreen;
	auto currentScreen = MultiWidgets::create<StartScreen>();
	currentScreen->setSize(size());
	currentScreen->setFixed();
	currentScreen->init();
	currentScreen->eventAddListener("nextScreen","playName",this);
	addChild(currentScreen);
}
void Session::changeScreen(const QByteArray & messageId){

	
	removeChildren();
	Radiant::IntrusivePtr<AbstractScreen> currentScreen;



	if(messageId == "playEnd") {
		currentScreen =  MultiWidgets::create<EndScreen>();
		currentScreen->eventAddListener("nextScreen","playStart",this);
	}
	else if(messageId == "playContent") {
		currentScreen =  MultiWidgets::create<ContentScreen>();
		currentScreen->eventAddListener("nextScreen","playEnd",this);
	}
	else if(messageId == "playName") {
		currentScreen =  MultiWidgets::create<NameScreen>();
		currentScreen->eventAddListener("nextScreen","playContent",this);
	}
	else {
		currentScreen = MultiWidgets::create<StartScreen>();
		currentScreen->eventAddListener("nextScreen","playName",this);
	}

	currentScreen->setSize(size());
	currentScreen->setFixed();
	currentScreen->init();
	addChild(currentScreen);
}

void Session::eventProcess(const QByteArray & messageId, Radiant::BinaryData & data)
{

	
	if(messageId == "playName" || messageId == "playStart" || messageId == "playEnd" || messageId == "playContent") changeScreen(messageId);

}